{include file="/sum/common/script" /}
<style>
    .handle-popover .tip {
        margin-bottom: 16px;
    }

    .question-filled {
        color: var(--el-color-warning);
        margin-right: 4px;
    }
    .stock_order-index .goods-item .goods-image {
        margin-right: 12px;
    }

    .stock_order-index .goods-item .goods-title {
        height: 20px;
        line-height: 20px;
        font-size: 14px;
        font-weight: 500;
        color: var(--sa-font);
    }

    .stock_order-index .goods-item .goods-subtitle {
        height: 16px;
        line-height: 16px;
        font-size: 12px;
        font-weight: 400;
        color: var(--sa-subfont);
        margin-bottom: 6px;
    }
    .stock_order-index .status.el-button {
        width: fit-content;
        height: 26px;
        padding: 0 12px;
        font-size: 12px;
        font-weight: 400;
        border-radius: 13px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        border: none;
    }

    .stock_order-index .status.status-primary {
        color: var(--el-color-primary);
        /* background: var(--sa-background-hex-active); */
    }

    .stock_order-index .status.status-success {
        color: #52c41a;
        /* background: rgba(82, 196, 26, 0.16); */
    }

    .stock_order-index .status.status-warning {
        color: #faad14;
        /* background: rgba(250, 173, 20, 0.16); */
    }

    .stock_order-index .status.status-danger {
        color: #ff4d4f;
        /* background: rgba(255, 77, 79, 0.16); */
    }

    .stock_order-index .status.status-info {
        color: #999999;
        /* background: rgba(153, 153, 153, 0.16); */
    }
</style>

<div id="index" class="stock_order-index panel panel-default panel-intro" v-cloak>
    <el-container class="panel-block">
        <el-header class="sa-header">
            <el-tabs class="sa-tabs" v-model="state.filter.data.status" @tab-change="onChangeTab">
                <el-tab-pane v-for="item in type.data.status" :key="item"
                             :label="`${item.name}${item.num ? '(' + item.num + ')' : ''}`" :name="item.type"></el-tab-pane>
            </el-tabs>
            <div class="sa-title sa-flex sa-row-between">
                <div class="sa-title-left">
                    <div class="left-name">进货订单</div>
                    <sa-filter-condition v-model="state.filter" @filter-delete="onChangeFilter">
                    </sa-filter-condition>
                </div>
                <div class="sa-title-right">
                    <el-button class="sa-button-refresh" icon="RefreshRight" @click="getData"></el-button>
                    <el-button class="sa-button-refresh" icon="Search" @click="onOpenFilter"></el-button>

                </div>
            </div>
        </el-header>
        <el-main class="sa-main">
            <el-table height="100%" class="sa-table" :data="state.data" stripe @selection-change="onChangeSelection" @sort-change="onChangeSort">
                <el-table-column type="selection" width="48" align="center"></el-table-column>
                <el-table-column prop="id" label="ID" min-width="90" sortable="custom">
                </el-table-column>

                <el-table-column label="商品" min-width="340">
                    <template #default="scope">
                        <div class="goods-item sa-flex sa-col-top">
                            <sa-image class="goods-image" :url="scope.row.goods.image" size="64"></sa-image>
                            <div class="right">
                                <div class="goods-title sa-table-line-1">{{scope.row.goods.title}}</div>
                                <div class="goods-subtitle sa-table-line-1">{{scope.row.goods.subtitle}}</div>
                                <div class="sa-table-line-1">￥{{scope.row.goods.stock_price}} * {{scope.row.goods_num}}</div>
                            </div>
                        </div>
                    </template>
                </el-table-column>

                <el-table-column label="应付金额" min-width="132">
                    <template #default="scope">
                        <div class="sa-table-line-1">
                            {{ scope.row.pay_fee }}
                        </div>
                    </template>
                </el-table-column>

                <el-table-column label="状态" min-width="80">
                    <template #default="scope">
                        <div class="status" :class="statusCode(scope.row).class">{{statusCode(scope.row).text}}</div>
                    </template>
                </el-table-column>

                <el-table-column min-width="268" align="center"  label="收货地址">
                    <template #default="scope">
                        <div class="address-item sa-flex sa-flex-col sa-col-top">
                            <div class="consignee">
                                <span>{{ scope.row.consignee }}</span>
                                <span>{{ scope.row.mobile }}</span>
                            </div>
                            <div class="name">
                                {{ scope.row.province_name }}/{{ scope.row.city_name }}/{{ scope.row.district_name }}
                            </div>
                            <div class="address sa-table-line-1">
                                {{ scope.row.address }}
                            </div>
                        </div>
                    </template>
                </el-table-column>
                <el-table-column min-width="268" align="center"  label="快递物流">
                    <template #default="scope">
                        <div>
                            <span>快递：{{ scope.row.express?.express_name || '-'}}</span>
                        </div>
                        <div>
                            <span>单号：{{ scope.row.express?.express_no || '-'}}</span>
                        </div>
                    </template>
                </el-table-column>
                <el-table-column label="创建时间" width="172">
                    <template #default="scope">
                        {{ scope.row.createtime || '-' }}
                    </template>
                </el-table-column>
                <el-table-column label="更新时间" width="172">
                    <template #default="scope">
                        {{ scope.row.updatetime || '-' }}
                    </template>
                </el-table-column>

                <el-table-column fixed="right" label="操作" min-width="180">
                    <template #default="scope">
                        {if $auth->check('sum/store/stock_order/pay')}
                        <el-button v-if="scope.row.status=='unpaid'" type="primary" link @click="onPay(scope.row.id)">支付</el-button>
                        {/if}
                        <el-popconfirm width="fit-content" confirm-button-text="确认" cancel-button-text="取消"
                                       title="确认收货这条记录?" @confirm="onComplete(scope.row.id)">
                            <template #reference>
                                {if $auth->check('sum/store/stock_order/complete')}
                                <el-button v-if="scope.row.status=='noget'" type="danger" link>确认收货</el-button>
                                {/if}
                            </template>
                        </el-popconfirm>
                    </template>
                </el-table-column>
            </el-table>
        </el-main>
        <el-footer class="sa-footer sa-flex sa-row-between sa-flex-wrap">
            <div class="sa-batch sa-flex">
                <div class="tip">
                    已选择 <span>{{batchHandle.data.length}}</span> 项</div>
                <div class="sa-flex">
                    {if $auth->check('sum/store/stock_order/delete')}
                    <el-button type="danger" :disabled="!batchHandle.data.length" @click="onBatchHandle('delete')">删除
                    </el-button>
                    {/if}
                </div>
            </div>
            <sa-pagination v-model="pagination" @pagination-change="getData"></sa-pagination>
        </el-footer>
    </el-container>
    <sa-filter v-model="state.filter" @filter-change="onChangeFilter"></sa-filter>
</div>